
package com.demo.user.exception;

/**
 * @author xiexiaohu
 */

public enum EErrorCode implements DisplayableError {
    // Default error
    COMM_INTERNAL_ERROR("COMM0001"),

    COMM_SERVER_ERROR("COMM0002"),

    FILE_PULL_ERROR("COMM0003"),

    ERROR_MSG_DO_NOT_HAVE_ACCESS("AUTHORIZE001", "没有权限访问此接口"),

    ERROR_MSG_MISSING_AUTH_HEADER("AUTHORIZE002", "Missing Authorization http header"),

    INVALID_ARGUMENT("ARG0001", "请检查输入参数"),
    USER_NAME_PWD_ERROR("1001", "账号或密码错误"),
    TOKEN_INVALID("1002", "令牌失效"),
    ACCOUNT_NOT_EXIST("1003", "该账号不存在"),

    ACCOUNT_DISABLED("2001", "用户被禁用"),
    EXCEED_LOGIN_RETRY_COUNT("2002", "因密码输入错误超过5次，该账号已被锁定10分钟，请稍后再试"),
    ACCOUNT_INACTIVE("2003", "用户未激活"),

    //Account related
    LOGIN_ACCOUNT_INVALID("0001", "用户名（手机/邮箱)无效"),
    EMAIL_INVALID("0002", "邮箱地址无效"),
    EMAIL_SEND_ERROR("0002", ""),
    MOBILE_INVALID("0003", "手机号码无效"),
    MOBILE_SAME_ERROR("0015", "只能更换成新号"),
    PASSWORD_INVALID("0004", "密码无效"),
    EMAIL_USED_BY_OTHER_ACCOUNT("0005", "该邮箱已被绑定，如需帮助请联系机构"),
    MOBILE_USED_BY_OTHER_ACCOUNT("0006", "该手机号已被绑定，如需帮助请联系机构"),
    USER_NOT_EXIST("0007", "用户不存在"),
    LOGIN_NAME_INVALID("8", "登录名无效"),
    REGISTER_ACCOUNT_INVALID("0009", "用户账号生成失败"),
    STATUS_INVALID("0010", "状态无效"),
    OLD_PASSWORD_ERROR("0011", "oldPassword: 旧密码输入错误，请重新输入"),
    REPEAT_PASSWORD_ERROR("0012", "确认密码和新密码不一致"),
    NEW_PASSWORD_ERROR("0013", "新密码和旧密码不能一样"),
    ID_CARD_NAME_CERTIFY_ERROR("0014", "身份证号和姓名不匹配"),

    SECURITY_VERIFY_CODE_WRONG("SECURITY_AUTH_0019", "验证码错误，请重新输入"),
    SECURITY_VERIFY_CODE_FAILURE_TIMES_OVER("SECURITY_AUTH_0021", "验证码失败次数过多，请10分钟之后再试"),
    SECURITY_SEND_VERIFY_CODE_FAIL("SECURITY_AUTH_0017", "验证码发送失败"),

    SECURITY_SEND_VERIFY_CODE_TOO_FAST("SECURITY_AUTH_0021", "一分钟以内不能重新发送验证码"),

    SECURITY_VERIFY_PRE_CODE_WRONG("SECURITY_AUTH_0020", "上一步验证码错误，请重新输入"),
    DATA_NOT_FUND_ERROR("9997", "数据不存在"),
    MOBILE_DUPLICATION("0016", "该手机号已存在"),

    ALIAS_DUPLICATED("60010", "别名重复"),

    //authorization related
    ROLE_DUPLICATED("3001", "角色名称重复"),
    DELETE_DEFAULT_ROLE("3002", "默认角色不能删除"),
    ROLE_USED_WHEN_DELETE("3003", "角色已经被使用不能删除"),
    ADMIN_NEED_USER_MEMBER("3004", "系统管理员必须含有至少一人（不包括部门、用户组）"),
    ROLE_NOT_EXIST("3005", "角色不存在"),
    DEFAULT_ROLE_NAME_CANNOT_CHANGE("3006", "默认角色名称不能更改"),
    ADMIN_CANNOT_REMOVE_SELF("3007", "修改失败，当前操作者必须具有“设置基础信息“的权限"),

    //organization
    NOT_FOUND_ORGANIZATION("4001", "找不到对应组织,请确认后重试"),
    CREATE_ORGANIZATION_FAILED("4002", "组织创建失败"),
    CREATE_DEPARTMENT_FAILED("4003", "部门创建失败"),
    EDIT_DEPARTMENT_FAILED("4003", "部门修改失败"),
    DELETE_DEPARTMENT_FAILED("4003", "部门删除失败"),
    DEPARTMENT_TREE_ERROR("4004", "部门树递归失败"),
    HAS_STAFF_ERROR("4005", "该员工已在组织内,请勿重复添加"),
    NO_STAFF_ERROR("4006", "该员工不存在,请确认"),
    NO_INVITE_USER_ERROR("4007", "邀请人无效,请确认"),
    INVITE_EXPIRE_TIME_ERROR("4008", "无效的过期时间"),
    INVITE_CODE_ERROR("4009", "无效邀请码"),
    INVITE_CODE_EXPIRE_TIME("4010", "无效邀请码"),
    NOT_POWER_EDIT("4011", "没有操作权限"),
    NOT_FOUND_DEPARTMENT("4012", "找不到对应部门,请确认后重试"),
    INVITE_APPLY_REPEAT("4013", "请勿重复提交"),
    INVITE_APPLY_NO_EXIT("4014", "申请已被处理或不存在,请确认"),
    NO_DEPARTMENT_ERROR("4015", "该部门不存在,请确认"),
    QR_CODE_ERROR("4016", "二维码转换失败"),
    QR_CODE_IMAGE_NO_EXIT("4017", "二维码图片不存在"),
    DEPARTMENT_TREE_OVER("4018", "部门不可超过三级"),

    //role
    ROLE_EMPTY_ORGANIZATION_CODE("40001", "组织编码不能为空"),
    ROLE_EMPTY_NAME("40002", "角色名称不能为空"),
    ROLE_EMPTY_CODE("40003", "角色编码不能为空"),
    ROLE_TREE_ERROR("40004", "权限树递归失败"),

    //certify idCard
    CERTIFY_APP_CODE_ERROR("50001", "AppCode错误"),
    CERTIFY_REQUEST_PATH_ERROR("50002", "请求的 Method、Path 或者环境错误"),
    CERTIFY_PARAMS_ERROR("50003", "参数错误"),
    CERTIFY_REQUEST_URL_ERROR("50004", "服务未被授权（或URL和Path不正确）"),
    CERTIFY_QUOTA_EXHAUSTED("50005", "套餐包次数用完"),
    CERTIFY_OTHER_ERROR("50006", "参数名错误 或 其他错误"),

    //sms
    SMS_NEED_LOGIN_ERROR("60001", "请先登陆后发送该验证码"),
    SMS_MOBILE_NO_EQUAL_ERROR("60002", "手机号与用户不匹配"),

    //common
    SMS_SEND_TYPE_ERROR("9998", "验证码类型错误"),
    INTERNAL_SERVER_ERROR("9999", "内部错误"),
    SITE_NOT_EXIST("8001", "站点不存在"),

    FILE_UPLOAD_ERROR("7001", "文件上传异常"),

    FILE_IMPORT_NAME_ERROR("7005", "文件格式错误"),

    SECRET_ENCRYPT_ERROR("7701", "加密失败"),
    SECRET_DECRYPT_ERROR("7702", "解密失败"),

    IDCARD_CERTIFY_ERROR("60003", "验证二要素失败"),
    OCR_IDCARD_ERROR("60001", "身份证识别失败"),
    OCR_IDCARD_FRONT_ERROR("60005", "识别失败, 请更换身份证（人像面）清晰完整的图重试"),
    OCR_IDCARD_BACK_ERROR("60006", "识别失败, 请更换身份证（国徽面）清晰完整的图重试"),

    IDCARD_ERROR("60002", "身份证图片错误"),
    ;

    private String errorCode;

    private String displayMsg;

    private Object[] args;

    private boolean bizError = true;

    private static final String DEFAULT_ERROR_MSG = "对不起, 服务出错了, 请稍后再试. 如错误重复出现请联系管理员.";

    EErrorCode(boolean bizError, String errorCode, String displayMsg) {
        this.errorCode = errorCode;
        this.displayMsg = displayMsg;
        this.bizError = bizError;
    }

    EErrorCode(String errorCode, String displayMsg) {
        this.errorCode = errorCode;
        this.displayMsg = displayMsg;
    }

    EErrorCode(String errorCode) {
        this.errorCode = errorCode;
        this.displayMsg = DEFAULT_ERROR_MSG;
        this.bizError = false;
    }

    @Override
    public boolean isBizError() {
        return this.bizError;
    }

    @Override
    public String getErrorCode() {
        return errorCode;
    }

    @Override
    public String getDisplayMsg() {
        return displayMsg;
    }

    /**
     * @return return the value of the var args
     */
    @Override
    public Object[] getArgs() {
        return args;
    }


    /**
     * 判断枚举是否包含该名称
     *
     * @param name
     * @return
     */
    public static boolean contains(String name) {
        try {
            EErrorCode eErrorCode = EErrorCode.valueOf(name);
            return true;
        } catch (IllegalArgumentException e) {
            return false;
        }

    }

}
